﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Security.Policy;
using Microsoft.Win32;

namespace NetMonitor.NetApp
{
    public partial class PropertyForm : Form
    {
        public PropertyForm()
        {
            InitializeComponent();
        }

        private string pointName;
        /// <summary>
        /// 节点的名称
        /// </summary>
        public string PointName
        {
            get { return pointName; }
            set { pointName = value; }
        }


        private string pointLocation;
        /// <summary>
        /// 节点的位置,用于标识位置(例如：北京),不参加计算
        /// </summary>
        public string PointLocation
        {
            get { return pointLocation; }
            set { pointLocation = value; }
        }

       
        private IPAddress pointIpaddress;
        /// <summary>
        /// 节点的IP地址
        /// </summary>
        public IPAddress PointIpaddress
        {
            get { return pointIpaddress; }
            set { pointIpaddress = value; }
        }


        private bool isValidate;
        /// <summary>
        /// 验证窗体的各参数是否合法
        /// </summary>
        public bool IsValidate
        {
            get { return isValidate; }
        }

        /// <summary>
        /// 取消 按钮的动作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_Cancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 确定 按钮的一系列动作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_Ok_Click(object sender, EventArgs e)
        {
            if (!CheckTb())
            {
                MessageBox.Show("请将参数填写完整");
                isValidate = false;
                return;
            }
            if (!CheckIPAddress())
            {
                MessageBox.Show("IP地址格式错误,请重新输入");
                isValidate = false;
                return;
            }
            pointName = tb_PointName.Text.Trim();//站点名称
            pointLocation = tb_PointLocation.Text.Trim();//地理位置 
            pointIpaddress = IPAddress.Parse(tb_PointIpaddress.Text.Trim());//IP地址
            isValidate = true;
            Close();
        }

        
        /// <summary>
        /// 检测IP地址
        /// </summary>
        /// <returns></returns>
        private bool CheckIPAddress()
        {
            try
            {
                IPAddress.Parse(tb_PointIpaddress.Text.Trim());
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }


        /// <summary>
        /// 检测节点名称,节点位置,节点IP地址控件中是否为空
        /// </summary>
        /// <returns></returns>
        private bool CheckTb()
        {
            if (tb_PointName.Text != String.Empty && tb_PointLocation.Text != String.Empty && tb_PointIpaddress.Text != String.Empty)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 将节点名,节点位置,节点IP地址显示在窗体上
        /// </summary>
        public void DisplayValue()
        {
            if (PointName != null && PointLocation != null && PointIpaddress != null)
            {
                tb_PointName.Text = PointName;
                tb_PointLocation.Text = PointLocation;
                tb_PointIpaddress.Text = PointIpaddress.ToString();
            }
        }

        
        private void button4_Click_1(object sender, EventArgs e)
        {
            Stream myStream2 = null;
            OpenFileDialog openFileDialog2 = new OpenFileDialog();

            openFileDialog2.InitialDirectory = "c:\\";
            openFileDialog2.Filter = "mp3 files (*.mp3)|*.mp3|wav files (*.wav)|*.wav|All files (*.*)|*.*";
            openFileDialog2.FilterIndex = 2;
            openFileDialog2.RestoreDirectory = true;
            //string SafeFileName2 = openFileDialog2.SafeFileName;

            textBox5.Text = openFileDialog2.FileName;

            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream2 = openFileDialog2.OpenFile()) != null)
                    {
                        using (myStream2)
                        {
                            if (openFileDialog2.ShowDialog() == DialogResult.OK)
                            {
                                // Insert code to read the stream here.
                            }


                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            textBox5.AppendText(openFileDialog2.FileName);
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            Stream myStream3 = null;
            OpenFileDialog openFileDialog3 = new OpenFileDialog();

            openFileDialog3.InitialDirectory = "c:\\";
            openFileDialog3.Filter = "mp3 files (*.mp3)|*.mp3|wav files (*.txt)|*.wav|All files (*.*)|*.*";
            openFileDialog3.FilterIndex = 2;
            openFileDialog3.RestoreDirectory = true;
            //string SafeFileName3 = openFileDialog3.SafeFileName;

            textBox6.Text = openFileDialog3.FileName;

            if (openFileDialog3.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream3 = openFileDialog3.OpenFile()) != null)
                    {
                        using (myStream3)
                        {
                            // Insert code to read the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            textBox6.AppendText(openFileDialog3.FileName);
        }



    }
}
